package com.yanqu.road.server.cmd.activity.dafuweng;

import com.yanqu.road.entity.activity.dafuweng.DFWBossData;
import com.yanqu.road.pb.monopoly.MonopolyProto;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.cmd.CrossUnionCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.cross.battle.DaFuWengActivity;
import com.yanqu.road.server.manager.cross.battle.DaFuWengMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.server.protocol.GameErrorCode;

@Cmd(code = Protocol.C_CROSS_DA_FU_WENG_GET_BOSS_DATA, desc = "大富翁跨服获取怪物数据")
public class CrossGetBossDataCmd extends CrossUnionCommand {

    private int activityId;
    private int bossId;
    private long serverId;
    private long userId;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        MonopolyProto.CrossGetBossDataReqMsg reqMsg = MonopolyProto.CrossGetBossDataReqMsg.parseFrom(packet.getBytes());
        activityId = reqMsg.getActivityId();
        bossId = reqMsg.getBossId();
        serverId = reqMsg.getServerId();
        userId = reqMsg.getUserId();
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {
        DaFuWengActivity daFuWengActivity = DaFuWengMgr.getDaFuWengActivity(activityId, groupId);
        if (daFuWengActivity == null) {
            MonopolyProto.GetBossDataRespMsg.Builder builder = MonopolyProto.GetBossDataRespMsg.newBuilder();
            builder.setRet(GameErrorCode.E_ACTIVITY_DFW_NO_IN_TIME);
            YanQuMessage yanQuMessage = YanQuMessageUtils.buildMessage(ClientProtocol.U_DA_FU_WENG_GET_BOSS_DATA, builder);
            MessageHelper.sendPacket(serverId, userId, yanQuMessage);
            return;
        }

        DFWBossData bossData = daFuWengActivity.getBossDataById(bossId);
        MonopolyProto.GetBossDataRespMsg.Builder builder = MonopolyProto.GetBossDataRespMsg.newBuilder();
        if (bossData == null) {
            builder.setRet(GameErrorCode.E_ACTIVITY_DFW_PARAM_ERROR);
        } else {
            builder.setRet(0);
            builder.setBossData(DaFuWengActivity.parseBossDataMsg(bossData));
        }

        YanQuMessage yanQuMessage = YanQuMessageUtils.buildMessage(ClientProtocol.U_DA_FU_WENG_GET_BOSS_DATA, builder);
        MessageHelper.sendPacket(serverId, userId, yanQuMessage);
    }

    @Override
    public void sendData() {

    }
}
